package org.example.service.error;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.stream.IntStream;

/**
 * @Author: tang
 * @Description:
 * @Date 2025/5/15 09:34
 */
@Component
public class ErrorSender implements CommandLineRunner {

    @Resource
    RabbitTemplate rabbitTemplate;

    @Override
    public void run(String... args) throws Exception {
        final Message message = MessageBuilder
                .withBody("hello world!".getBytes(StandardCharsets.UTF_8))
                .setContentType(MessageProperties.CONTENT_TYPE_BYTES)
                .setMessageId(UUID.randomUUID().toString())
                .build();

        IntStream.range(0,2)
                .forEach(i -> {
//                    rabbitTemplate.send("ex.tang.error", message);
                    rabbitTemplate.send("ex.tang.error.1", message);
                });

    }
}
